﻿using SAPDownload.Service.Utility;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Specialized;

namespace TestProject
{
    
    
    /// <summary>
    ///This is a test class for SqlUtilityDataControllerTest and is intended
    ///to contain all SqlUtilityDataControllerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SqlUtilityDataControllerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AnalysisGetDate
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SAPDownload.Service.exe")]
        public void AnalysisGetDateTest()
        {
           // SqlUtility_Accessor target = new SqlUtility_Accessor(); // TODO: Initialize to an appropriate value
           // string expression = "GETDATE(10,Y)"; // TODO: Initialize to an appropriate value
           // string expected = "20201007"; // TODO: Initialize to an appropriate value
           // string actual;
           //// actual = target.AnalysisGetDate(expression);
           // Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for AnalysisConditional
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SAPDownload.Service.exe")]
        public void AnalysisConditionalTest()
        {
            string sqlText = "select *,getdate() as 'Date' from MARD WHERE Date=getDate() AND WERKS='AHAE' AND Date1=GETDATE(-2,M)"; // TODO: Initialize to an appropriate value
            string expected = "select *,'20101007' as 'Date' from MARD WHERE Date='20101007' AND WERKS='AHAE' AND Date1='20100807'"; // TODO: Initialize to an appropriate value
            string actual;
            actual = SqlUtility.AnalysisFunctions(sqlText);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for AnalysisSql
        ///</summary>
        [TestMethod()]
        public void AnalysisSqlTest()
        {
            string sqlText = "select *,getdate(),'VENDOR' from MARD WHERE Date=getDate() AND WERKS='AHAE' AND Date1=GETDATE(-2,M)"; // TODO: Initialize to an appropriate value
            string expected = "SELECT  *,'20101007' from MARD WHERE Date='20101007' AND WERKS='AHAE' AND Date1='20100807'"; // TODO: Initialize to an appropriate value
            NameValueCollection nvConstColumns = new NameValueCollection(); // TODO: Initialize to an appropriate value
          //  nvConstColumns.Add("'VENDOR' as 'VENDORCODE'", "'VENDOR' as 'VENDORCODE'");
            NameValueCollection nvConstColumnsExpected = new NameValueCollection(); // TODO: Initialize to an appropriate value
            nvConstColumnsExpected.Add("VENDOR", "VENDOR");
            string actual = SqlUtility.AnalysisSql(sqlText, out nvConstColumns);
            Assert.AreEqual(nvConstColumnsExpected[0], nvConstColumns[0]);
            Assert.AreEqual(expected, actual);
        }
    }
}
